export { analyzeClientSide }

import { getConfigValueRuntime } from '../page-configs/getConfigValue.js'
import type { PageConfigRuntime } from '../page-configs/PageConfig.js'
import type { PageFile } from './getPageFileObject.js'
import { analyzePageClientSide } from './analyzePageClientSide.js'

function analyzeClientSide(
  pageConfig: PageConfigRuntime | null,
  pageFilesAll: PageFile[],
  pageId: string
): { clientEntryLoaded: boolean; isClientRouting: boolean } {
  // V1 design
  if (pageConfig) {
    const isClientRouting = getConfigValueRuntime(pageConfig, 'clientRouting', 'boolean')?.value ?? false
    const clientEntryLoaded = getConfigValueRuntime(pageConfig, 'clientEntryLoaded', 'boolean')?.value ?? false
    return { clientEntryLoaded, isClientRouting }
  } else {
    // TODO/v1-release: remove
    // V0.4 design
    const { isHtmlOnly, isClientRouting } = analyzePageClientSide(pageFilesAll, pageId)
    return { clientEntryLoaded: !isHtmlOnly, isClientRouting }
  }
}
